package curator.leaderLatch.util;

import java.net.InetAddress;
import java.net.UnknownHostException;

import org.apache.log4j.Logger;

/**
 * Created by Administrator on 2016/7/4.
 */
public final class NetworkUtil {
	private NetworkUtil(){}
	private static Logger LOGGER = Logger.getLogger("runLog");

	/**
	 * getMyHostName
	 * @return retStr
	 */
    public static String getMyHostName(){
        String retStr = null;
        InetAddress ip = null;
        try {
            ip = InetAddress.getLocalHost();
            retStr = ip.getHostName();
        } catch (UnknownHostException e) {
            LOGGER.error(e.getMessage(), e);
        }
        return retStr;
    }
	/**
	 * getHostAddress
	 * @return retStr
	 */
    public static String getMyHostAddress(){
        String retStr = null;
        InetAddress ip = null;
        try {
            ip = InetAddress.getLocalHost();
            retStr = ip.getHostAddress();
        } catch (UnknownHostException e) {
            LOGGER.error(e.getMessage(), e);
        }
        return retStr;
    }
    
    public static void main(String[] args){
    	System.out.println( getMyHostName());
    	System.out.println( getMyHostAddress());
    }
}